package com.example.demo1.generator.codedesign.model;

import java.sql.Types;

/**
 * 属性类型
 * 
 * @author lake
 *
 */
public enum PropertyType {

	INTEGER("Integer", "INTEGER"), 
	STRING("String", "VARCHAR"), 
	DATE("java.util.Date", "TIMESTAMP"), 
	DATETIME("java.util.Date", "TIMESTAMP"), 
	DECIMAL("java.math.BigDecimal", "DECIMAL"), 
	LONG("Long", "BIGINT"), 
	LONGVARCHAR("String", "LONGVARCHAR"), 
	BOOLEAN("Boolean", "BOOLEAN"), 
	UNSUPPORT("UNSUPPORT", "未知类型");

	private String code;
	private String mybatisType;

	private PropertyType(String c, String mybatis) {
		this.code = c;
		this.mybatisType = mybatis;
	}

	public String getCode() {
		return this.code;
	}

	public String getMybatisType() {
		return mybatisType;
	}

	/**
	 * 
	 * @param code
	 *            参考{@link Types}
	 * @return
	 */
	public static PropertyType getJavaType(int code) {
		PropertyType jdbcType = null;

		switch (code) {
		case Types.VARCHAR:
		case Types.CHAR:
		case Types.BLOB:
			jdbcType = PropertyType.STRING;
			break;
		case Types.INTEGER:
		case Types.TINYINT:
		case Types.SMALLINT:
			jdbcType = PropertyType.INTEGER;
			break;
		case Types.BIGINT:
			jdbcType = PropertyType.LONG;
			break;
		case Types.TIMESTAMP:
		case Types.TIME:
			jdbcType = PropertyType.DATETIME;
			break;
		case Types.DATE:
			jdbcType = PropertyType.DATE;
			break;
		case Types.DECIMAL:
		case Types.DOUBLE:
		case Types.FLOAT:
			jdbcType = PropertyType.DECIMAL;
			break;
		case Types.LONGVARCHAR:
			jdbcType = PropertyType.LONGVARCHAR;
			break;
		case Types.BIT:
		case Types.BOOLEAN:
			jdbcType = PropertyType.BOOLEAN;
			break;
		default:
			jdbcType = PropertyType.UNSUPPORT;
		}
		return jdbcType;
	}

}
